package cn.jcet.mapreduce.group;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author 鲜磊
 * @Date 2020/12/14 17:59
 */
public class OrderMapper extends Mapper<LongWritable,Text,OrderBean,NullWritable> {

    private OrderBean k = new OrderBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // 转换为字符串
        String line = value.toString();
        // 进行分割
        String[] fileds = line.split("\t");
        // 获取编号
        k.setOrder_id(Integer.parseInt(fileds[0]));
        // 获取价格
        k.setPrice(Double.parseDouble(fileds[2]));
        // 写出
        context.write(k,NullWritable.get());
    }
}
